package com.seamtop.cuber.common.util;

import java.util.Random;

/**
 * Created by zongjunfeng on 2015/9/24.
 */
public class RandomUtil {



    public static String generatorReducerId(String keyPrefix){
        String val = randomAllChar(2);
        String result = "";
        if(!StringUtil.isEmpty(keyPrefix)){
            result = keyPrefix + val;
        }else{
            result = val;
        }
        return result;
    }


    public static String randomAllChar(int length){
        String val = "";
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
            if ("char".equalsIgnoreCase(charOrNum)) {
                int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
                val += (char) (choice + random.nextInt(26));
            } else if ("num".equalsIgnoreCase(charOrNum)) { // ����
                val += String.valueOf(random.nextInt(10));
            }
        }
        return val;
    }

    public static void main(String [] args){
    }
}
